<%-- 
    Document   : register
    Created on : Sep 15, 2011, 8:31:15 AM
    Author     : Arturia
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Register</title>
        <link href="css/style.css" rel="stylesheet" type="text/css"/>
        <link href="css/bannerstyle.css" rel="stylesheet" type="text/css"/>
        <link href="css/TableCSS.css" rel="stylesheet" type="text/css"/>

        <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />

        <script type="text/javascript">
            function validate(element){
                var regExp = null;
                switch (element){
                    case document.getElementById("username"):
                        if(element.value.toString().length <= 50 && element.value.toString().length > 0){
                            document.getElementById("username_error").style.visibility = "hidden";
                            document.getElementById("username").style.borderColor = "#333333";
                            document.getElementById("registerbutton").disabled = false;
                            return true;
                        }else{
                            document.getElementById("username_error").style.visibility = "visible";
                            document.getElementById("username_error").textContent = "Must be filled & less than 50 characters";
                            //document.getElementById("username").focus();
                            document.getElementById("username").style.borderColor = "red";
                            document.getElementById("registerbutton").disabled = true;
                            return false;
                        }
                        break;
                    case document.getElementById("password"):
                        if(element.value.toString().length <= 50 && element.value.toString().length > 0){
                            document.getElementById("password_error").style.visibility = "hidden";
                            document.getElementById("registerbutton").disabled = false;
                            document.getElementById("password").style.borderColor = "#333333";
                            return true;
                        }else{
                            document.getElementById("password_error").style.visibility = "visible";
                            //document.getElementById("password").focus();
                            document.getElementById("password").style.borderColor = "red";
                            document.getElementById("registerbutton").disabled = true;
                            return false;
                        }
                        break;
                        case document.getElementById("re-password"):
                        if(element.value.toString() == document.getElementById("password").value.toString()){
                            document.getElementById("pass_error").style.visibility = "hidden";
                            document.getElementById("re-password").style.borderColor = "#333333";
                            document.getElementById("registerbutton").disabled = false;
                            return true;
                        }else{
                            document.getElementById("pass_error").style.visibility = "visible";
                            //document.getElementById("re-password").focus();
                            document.getElementById("re-password").style.borderColor = "red";
                            document.getElementById("registerbutton").disabled = true;
                            return false;
                        }
                        break;
                    case document.getElementById("realname"):
                        if(element.value.toString().length <= 50 && element.value.toString().length > 0){
                            document.getElementById("realname_error").style.visibility = "hidden";
                            document.getElementById("registerbutton").disabled = false;
                            document.getElementById("realname").style.borderColor = "#333333";
                            return true;
                        }else{
                            document.getElementById("realname_error").style.visibility = "visible";
                            //document.getElementById("realname").focus();
                            document.getElementById("realname").style.borderColor = "red";
                            document.getElementById("registerbutton").disabled = true;
                            return false;
                        }
                        break;
                    case document.getElementById("birth"):
                        regExp = /(?:0[1-9]|[12][0-9]|3[01])\/(?:0[1-9]|1[0-2])\/(?:19|99\d{2})/;
                        if(element.value.match(regExp) && element.value.toString().length > 0){
                            document.getElementById("birth_error").style.visibility = "hidden";
                            document.getElementById("registerbutton").disabled = false;
                            document.getElementById("birth").style.borderColor = "#333333";
                            return true;
                        }else{
                            document.getElementById("birth_error").style.visibility = "visible";
                            //document.getElementById("birth").focus();
                            document.getElementById("birth").style.borderColor = "red";
                            document.getElementById("registerbutton").disabled = true;
                            return false;
                        }
                        break;
                    case document.getElementById("email"):
                        regExp = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
                        if(element.value.toString().length <= 50 && element.value.match(regExp) && element.value.toString().length > 0){
                            document.getElementById("email_error").style.visibility = "hidden";
                            document.getElementById("email").style.borderColor = "#333333";
                            document.getElementById("registerbutton").disabled = false;
                            return true;
                        }else{
                            document.getElementById("email_error").style.visibility = "visible";
                            //document.getElementById("email").focus();
                            document.getElementById("email").style.borderColor = "red";
                            document.getElementById("registerbutton").disabled = true;
                            return false;
                        }
                        break;
                    case document.getElementById("address"):
                        if(element.value.toString().length <= 500 && element.value.toString().length > 0){
                            document.getElementById("address_error").style.visibility = "hidden";
                            document.getElementById("address").style.borderColor = "#333333";
                            document.getElementById("registerbutton").disabled = false;
                            return true;
                        }else{
                            document.getElementById("address_error").style.visibility = "visible";
                            //document.getElementById("address").focus();
                            document.getElementById("address").style.borderColor = "red";
                            document.getElementById("registerbutton").disabled = true;
                            return false;
                        }
                        break;
                    case document.getElementById("city"):
                        if(element.value.toString().length <= 50 && element.value.toString().length > 0){
                            document.getElementById("city_error").style.visibility = "hidden";
                            document.getElementById("city").style.borderColor = "#333333";
                            document.getElementById("registerbutton").disabled = false;
                            return true;
                        }else{
                            document.getElementById("city_error").style.visibility = "visible";
                            //document.getElementById("city").focus();
                            document.getElementById("city").style.borderColor = "red";
                            document.getElementById("registerbutton").disabled = true;
                            return false;
                        }
                        break;
                    case document.getElementById("phone"):
                        regExp = /^[0-9]+$/;
                        if(element.value.toString().length <= 50 && element.value.match(regExp) && element.value.toString().length > 0){
                            document.getElementById("phone_error").style.visibility = "hidden";
                            document.getElementById("phone").style.borderColor = "#333333";
                            document.getElementById("registerbutton").disabled = false;
                            return true;
                        }else{
                            document.getElementById("phone_error").style.visibility = "visible";
                            //document.getElementById("phone").focus();
                            document.getElementById("phone").style.borderColor = "red";
                            document.getElementById("registerbutton").disabled = true;
                            return false;
                        }
                        //break;
                }
            }
            function checkNULL(){
                if(document.getElementById("username").value.toString().length == 0){
                    document.getElementById("username_error").textContent = "Must be filled & less than 50 characters";
                    document.getElementById("username").style.borderColor = "red";
                    document.getElementById("username_error").style.visibility = "visible";
                    document.getElementById("password_error").style.visibility = "collapse";
                    document.getElementById("pass_error").style.visibility = "collapse";
                    document.getElementById("realname_error").style.visibility = "collapse";
                    document.getElementById("birth_error").style.visibility = "collapse";
                    document.getElementById("email_error").style.visibility = "collapse";
                    document.getElementById("address_error").style.visibility = "collapse";
                    document.getElementById("city_error").style.visibility = "collapse";
                    document.getElementById("phone_error").style.visibility = "collapse";
                    document.getElementById("username").focus();
                    return false;
                } else if(document.getElementById("password").value.toString().length == 0){
                    document.getElementById("username_error").style.visibility = "collapse";
                    document.getElementById("password_error").style.visibility = "visible";
                    document.getElementById("password").style.borderColor = "red";
                    document.getElementById("pass_error").style.visibility = "collapse";
                    document.getElementById("realname_error").style.visibility = "collapse";
                    document.getElementById("birth_error").style.visibility = "collapse";
                    document.getElementById("email_error").style.visibility = "collapse";
                    document.getElementById("address_error").style.visibility = "collapse";
                    document.getElementById("city_error").style.visibility = "collapse";
                    document.getElementById("phone_error").style.visibility = "collapse";
                    document.getElementById("password").focus();
                    return false;
                }else if (document.getElementById("re-password").value.toString() !== document.getElementById("password").value.toString()){
                    document.getElementById("username_error").style.visibility = "collapse";
                    document.getElementById("password_error").style.visibility = "collapse";
                    document.getElementById("pass_error").style.visibility = "visible";
                    document.getElementById("re-password").style.borderColor = "red";
                    document.getElementById("realname_error").style.visibility = "collapse";
                    document.getElementById("birth_error").style.visibility = "collapse";
                    document.getElementById("email_error").style.visibility = "collapse";
                    document.getElementById("address_error").style.visibility = "collapse";
                    document.getElementById("city_error").style.visibility = "collapse";
                    document.getElementById("phone_error").style.visibility = "collapse";
                    document.getElementById("re-password").focus();
                    return false;
                } else if (document.getElementById("realname").value.toString().length == 0){
                    document.getElementById("username_error").style.visibility = "collapse";
                    document.getElementById("password_error").style.visibility = "collapse";
                    document.getElementById("pass_error").style.visibility = "collapse";
                    document.getElementById("realname_error").style.visibility = "visible";
                    document.getElementById("realname").style.borderColor = "red";
                    document.getElementById("birth_error").style.visibility = "collapse";
                    document.getElementById("email_error").style.visibility = "collapse";
                    document.getElementById("address_error").style.visibility = "collapse";
                    document.getElementById("city_error").style.visibility = "collapse";
                    document.getElementById("phone_error").style.visibility = "collapse";
                    document.getElementById("realname").focus();
                    return false;
                } else if (document.getElementById("birth").value.toString().length == 0){
                    document.getElementById("username_error").style.visibility = "collapse";
                    document.getElementById("password_error").style.visibility = "collapse";
                    document.getElementById("pass_error").style.visibility = "collapse";
                    document.getElementById("realname_error").style.visibility = "collapse";
                    document.getElementById("birth_error").style.visibility = "visible";
                    document.getElementById("birth").style.borderColor = "red";
                    document.getElementById("email_error").style.visibility = "collapse";
                    document.getElementById("address_error").style.visibility = "collapse";
                    document.getElementById("city_error").style.visibility = "collapse";
                    document.getElementById("phone_error").style.visibility = "collapse";
                    document.getElementById("birth").focus();
                    return false;
                } else if (document.getElementById("email").value.toString().length == 0){
                    document.getElementById("username_error").style.visibility = "collapse";
                    document.getElementById("password_error").style.visibility = "collapse";
                    document.getElementById("pass_error").style.visibility = "collapse";
                    document.getElementById("realname_error").style.visibility = "collapse";
                    document.getElementById("birth_error").style.visibility = "collapse";
                    document.getElementById("email_error").style.visibility = "visible";
                    document.getElementById("email").style.borderColor = "red";
                    document.getElementById("address_error").style.visibility = "collapse";
                    document.getElementById("city_error").style.visibility = "collapse";
                    document.getElementById("phone_error").style.visibility = "collapse";
                    document.getElementById("email").focus();
                    return false;
                } else if (document.getElementById("address").value.toString().length == 0){
                    document.getElementById("username_error").style.visibility = "collapse";
                    document.getElementById("password_error").style.visibility = "collapse";
                    document.getElementById("pass_error").style.visibility = "collapse";
                    document.getElementById("realname_error").style.visibility = "collapse";
                    document.getElementById("birth_error").style.visibility = "collapse";
                    document.getElementById("email_error").style.visibility = "collapse";
                    document.getElementById("address_error").style.visibility = "visible";
                    document.getElementById("address").style.borderColor = "red";
                    document.getElementById("city_error").style.visibility = "collapse";
                    document.getElementById("phone_error").style.visibility = "collapse";
                    document.getElementById("address").focus();
                    return false;
                } else if (document.getElementById("city").value.toString().length == 0){
                    document.getElementById("username_error").style.visibility = "collapse";
                    document.getElementById("password_error").style.visibility = "collapse";
                    document.getElementById("pass_error").style.visibility = "collapse";
                    document.getElementById("realname_error").style.visibility = "collapse";
                    document.getElementById("birth_error").style.visibility = "collapse";
                    document.getElementById("email_error").style.visibility = "collapse";
                    document.getElementById("address_error").style.visibility = "collapse";
                    document.getElementById("city_error").style.visibility = "visible";
                    document.getElementById("city").style.borderColor = "red";
                    document.getElementById("phone_error").style.visibility = "collapse";
                    document.getElementById("city").focus();
                    return false;
                } else if (document.getElementById("phone").value.toString().length == 0){
                    document.getElementById("username_error").style.visibility = "collapse";
                    document.getElementById("password_error").style.visibility = "collapse";
                    document.getElementById("pass_error").style.visibility = "collapse";
                    document.getElementById("realname_error").style.visibility = "collapse";
                    document.getElementById("birth_error").style.visibility = "collapse";
                    document.getElementById("email_error").style.visibility = "collapse";
                    document.getElementById("address_error").style.visibility = "collapse";
                    document.getElementById("city_error").style.visibility = "collapse";
                    document.getElementById("phone_error").style.visibility = "visible";
                    document.getElementById("phone").style.borderColor = "red";
                    document.getElementById("phone").focus();
                    return false;
                }else{
                    return true;
                }
            }

            function checkExitsUserName(isExits){
                if(isExits == "true"){
                    document.getElementById("username_error").style.visibility = "visible";
                    document.getElementById("username_error").textContent = "Username is already exits!";
                    
                }else{
                    document.getElementById("username_error").style.visibility = "collapse";
                }
            }

            function checkSearch(){
                if (document.getElementById("searchText").value.toString().length == 0){
                    alert("Must input somrthing!")
                    return false;
                }else{
                    return true;
                }
            }
        </script>
        <%
                    String userExits = (String) request.getAttribute("USERNAMEEXITS");
                    String isExits = "";
                    if (userExits == null || userExits == "false") {
                        isExits = "false";
                    } else {
                        isExits = "true";
                    }
        %>
    </head>
    <body onload='checkExitsUserName("<%=isExits%>")'>
        <div id="header-wrap">
            <div id="header">
                <div style="margin:0px; text-align: left; float: left;"> <span style="color: #FFFFFF; font-family:'Arial Black',Gadget,sans-serif; font-size: 20px; font-weight: bold; letter-spacing: -2px;"><a href="index.jsp" style="color: #FFF; text-decoration: none;" title="Awesomebooks.com">AWESOMEBOOKS</a></span> <a style="color: #FFF; font-size: 18px; font-family: Georgia, 'Times New Roman', Times, serif; font-style:italic; font-weight:normal; text-decoration: none;" href="index.jsp" title="Find your own book">Find your own book</a> 	</div>
                <ul class="menu">

                    <!-- Begin Simple Item Without Drop -->
                    <li class="">
                        <a href="newrelease.jsp">New Release</a>
                    </li>
                    <li class="">
                        <a href="bestseller.jsp">Best Seller</a>
                    </li>
                    <li class="">
                        <a href="bookreview.jsp">Books Review</a>
                    </li>

                    <li class="drop">
                        <a href="#">Catalogs</a>
                        <span class="toggle">&nbsp;</span>
                        <ul>
                            <li><a href="Controller?Action=Search&searchText=literature&Category=true">Literature</a></li>
                            <li><a href="Controller?Action=Search&searchText=life style&Category=true">Life Style</a></li>
                            <li><a href="Controller?Action=Search&searchText=tutorial&Category=true">Tutorial</a></li>
                            <li><a href="Controller?Action=Search&searchText=discovery&Category=true">Discovery</a></li>
                            <li><a href="Controller?Action=Search&searchText=science&Category=true">Science</a></li>
                            <li><a href="Controller?Action=Search&searchText=kids&Category=true">Kids</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
            <div id="underheader">
                <form action="Controller" onsubmit="return checkSearch()" method="POST">
                    <span id="searchbox" style="width:50%">
                        <input id="searchText" name="searchText" type="text" style="width:250px; border:1px solid #333333" />
                        <input name="Action" type="submit" value="Search" id="button" />
                    </span>
                    <span id="user" style="width:50%">
                        <a href="login.jsp">Login</a> |
                        <a href="register.jsp">Register</a>
                    </span>
                </form>
            </div>
        </div>
        <center>
            <br/>
            <div id="registerForm">
                <form action="Controller" method="post">
                    <fieldset>
                        <legend>Login Details</legend>
                        <div><label>Username</label><input name="username" id="username" type="text" style="border-color: #333333" onblur="validate(document.getElementById('username'))"/></div>
                        <div><label>Password</label><input name="password" id="password" type="password" style="border-color: #333333" onblur="validate(document.getElementById('password'))"/></div>
                        <div><label>Retype Password</label><input name="re-password" id="re-password" type="password" onblur="validate(document.getElementById('re-password'))" style="border-color: #333333"/></div>
                    </fieldset>
                    <fieldset>
                        <legend>User Details</legend>
                        <div><label>Real Name</label><input name="realname" id="realname" type="text" onblur="validate(document.getElementById('realname'))" style="border-color: #333333"/></div>
                        <div><label>Date of Birth</label><input name="birth" id="birth" type="text" onblur="validate(document.getElementById('birth'))" style="border-color: #333333"/></div>
                        <div><label>Email</label><input name="email" id="email" type="text" onblur="validate(document.getElementById('email'))"style="border-color: #333333"/></div>
                        <div><label>Address</label><input name="address" id="address" type="text" onblur="validate(document.getElementById('address'))"style="border-color: #333333"/></div>
                        <div><label>City</label><input name="city" id="city" type="text" onblur="validate(document.getElementById('city'))"style="border-color: #333333"/></div>
                        <div><label>Phone</label><input name="phone" id='phone' type="text" onblur="validate(document.getElementById('phone'))"style="border-color: #333333"/></div>
                    </fieldset>
                    <div id="errorcheck">
                        <label id="username_error" style="color: red; visibility: collapse;width: 300px"></label><br/>
                        <label id="password_error" style="color: red; visibility: collapse; width: 300px">Password must not be null</label><br/>
                        <label id="pass_error" style="color: red; visibility: collapse; width: 300px">Password do not match!</label>
                        <label id="realname_error" style="color: red;visibility: collapse; width: 300px">Must be less than 50 characters</label>
                        <label id="birth_error" style="color: red; visibility: collapse; width: 300px">Must be DD/MM/YY</label>
                        <label id="email_error" style="color: red; visibility: collapse; width: 300px">Your email address is not valid</label>
                        <label id="address_error" style="color: red; visibility: collapse; width: 300px">Must be less than 50 characters</label>
                        <label id="city_error" style="color: red; visibility: collapse; width: 300px">Must be less than 50 characters</label>
                        <label id="phone_error" style="color: red; visibility: collapse; width: 300px">Must be filled & less than 50 characters</label>
                    </div>
                    <button id ="registerbutton" name="Action" value="Register" type="submit" onclick="return checkNULL()" style="position: relative; top: -355px">Register</button>
                </form>
            </div>
        </center>
        <br/>
    </body>
</html>
